package com.shoplook2025.brand.api.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shoplook2025.brand.model.Brand;
import com.shoplook2025.brand.service.BrandService;
import com.shoplook2025.core.utils.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yan
 * @date 2025/8/25
 */
/**
 * 注解@RefreshScope，标注在有@Value注解的类上，表示@Value注解所获取的远程配置项动态刷新
 */
@RefreshScope
@RestController
@RequestMapping(value = "/api/brand",produces = MediaType.APPLICATION_JSON_VALUE)
public class BrandApi {

    private BrandService brandService;
    @Autowired
    public void setBrandService(BrandService brandService) {
        this.brandService = brandService;
    }

    @GetMapping
    public ResponseEntity<JsonResult<Page<Brand>>> findAll(Integer pageSize, Integer pageNo, Brand brand) {
        Page<Brand> page = Page.of(pageNo,pageSize);
        page = brandService.findAll(page,brand);
        return ResponseEntity.ok(JsonResult.success(page));

    }

    @GetMapping("/id/{id}")
    public ResponseEntity<JsonResult<Brand>> findById(@PathVariable Integer id) {
        Brand brand = brandService.findById(id);
        return ResponseEntity.ok(JsonResult.success(brand));
    }
}
